namespace Vanilla.UI

import System

partial class Gadget:
	
	virtual def Draw (b as Brush):
		Theme.Draw(self, b)
		DrawContents(b)
	
	virtual def DrawContents (b as Brush):
		pass
	
	// REDRAW
	dirty_area as Rect
	
	drawing_paused as short = 0
	DrawingPaused as bool:
		get:
			return true if drawing_paused != 0
			//return true if HasParent and Parent.DrawingPaused
			return false
	
	def PauseDrawing ():
		dirty_area = Rect() unless DrawingPaused
		drawing_paused++
	
	def ResumeDrawing ():
		drawing_paused--
		unless (DrawingPaused):
			RedrawArea(dirty_area)
	
	virtual def RedrawArea (area as Rect):
		//print "${GetType()}.RedrawArea(${area})"
	
		if DrawingPaused:
			dirty_area += area
			return
		if HasParent:
			Parent.RedrawArea(Rect(area.X+Rect.X, area.Y+Rect.Y, area.X2+Rect.X, area.Y2+Rect.Y))
	
	def Redraw():
		RedrawArea(Rect(0,0,Rect.Width,Rect.Height))
